<?php
/**
 * 滚动图片 //1品牌宣传 2品牌活动 3商场宣传 4商场活动
 * @author Ice <iceinto@mallog.com.cn>
 */
class SlideModel extends BaseModel
{
	//自动验证
	protected $_validate = array(
			array("title", "require", "名称必须！", 1)
	);

	/**
	 * 获取宣传图
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function getPropagandas($mid, $bid){
		if($mid && $bid){
			$this->error('品牌和商场不能同时存在！');
		}else if(!$mid && !bid){
			$this->error('品牌和商场不能同时为空！');
		}
		$map = array();
		$map['fid'] = 0;
		$map['bid'] = 0;
		if($mid){
			$map['mid'] = $mid;
			$map['type'] = 3;
		}
		if($bid){
			$map['bid'] = $bid;
			$map['type'] = 1;
		}
		$ads = $this->where($map)->select();
		$this->setImage(&$ads);
		return $ads;
	}

	/**
	 * 获取活动图
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function getActivites($mid, $fid, $bid){
		$map = array();
		$map['fid'] = 0;
		$map['bid'] = 0;
		if($mid && !$fid && !$bid){
			$map['mid'] = $mid;
			$map['type'] = 4;
		}
		if($mid && $fid && $bid){
			$map['mid'] = $mid;
			$map['fid'] = $fid;
			$map['bid'] = $bid;
			$map['type'] = 2;
		}
		$ads = $this->where($map)->select();
		$this->setImage(&$ads);
		return $ads;
	}

	/**
	 * 设置图片信息
	 * @param array $ads 列表数组
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	private function setImage($ads){
		if($ads){
			foreach($ads as $key=>$ad){
				$ads[$key]['image_url'] = $this->getManagedUrl($ad['image'],'slide');
			}
		}
	}
}

?>